<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>新发生生产计划登记预览页面</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/ProductDesign/module(1).css" />
    <style type="text/css">

    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">生产管理</a></li>
            <li class="breadcrumb-item"><a href="#">生产计划管理</a></li>
            <li class="breadcrumb-item active" aria-current="page">新发生生产计划登记</li>
        </ol>
    </nav>
</div>
<div style="margin-bottom: 2px">
    <div style="display: inline;margin-left: 83%;">
        <button class="btn btn-primary" id="submit">提交</button>
        <button class="btn btn-primary" id="back">返回</button>
<%--        <button class="btn btn-primary">清除</button>--%>
    </div>
</div> <!-- 此div改用栅格来做 -->
<div id="designListBox">
    <div style="text-align: center">
        <h3>生产计划单</h3>
    </div>
    <div style="padding: 30px">
        <table class="tbl1">
            <tr>
                <td class="col1">生产理由：</td>
                <td class="col2">新发计划</td>
                <td class="col1">供货时间：</td>
                <td class="col2" id="deliveryTime"></td>
            </tr>
            <tr>
                <td class="col1">登记人：</td>
                <td colspan="1"><input type="text" class="txt_under_line" id="registrants"></td>
                <td class="col1">登记时间：</td>
                <td colspan="2" id="checkInTime"></td>
            </tr>
        </table>

        <table class="table table-bordered" style="margin: 15px auto;">
            <thead>
            <tr>
                <th>序号</th><th>产品名称</th><th>产品编号</th>
                <th>描述</th><th>数量</th><th>单位</th>
                <th>单价（元）</th><th>小计（元）</th>
            </tr>
            </thead>
            <tbody id="template">
            </tbody>

        </table>

        <table class="tbl3">
            <tr>
                <td class="col1" style="width: 15%;" >总件数：</td>
                <td class="col2">30.00</td>
                <td class="col1" style="width: 15%;">总金额：</td>
                <td class="col2">30.00</td>
            </tr>
            <tr>
                <td class="col1">备注：</td>
                <td colspan="3" style="padding-top: 5px">
                    <textarea rows="4" cols="100" id="remarks"></textarea>
                </td>
            </tr>
        </table>
    </div>
</div>
<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    $(function () {
        //初始化页面
        init();

        //点击返回按钮跳转到上一页
        $("#back").click(function (){
            window.history.back();
        })
        //点击提交按钮提交数据,并判断是否已经提交过，如果已经提交过则提示用户不能再提交
        $("#submit").click(function () {
            //先判断sessionStorage中是否有提交成功的标识
            let submit = sessionStorage.getItem("submit");
            if (submit == "true") {
                alert("您已经提交过了，不能再提交了");
                return;
            }
            //获取页面中的数据
            let registrants = $("#registrants").val();
            let checkInTime = $("#checkInTime").text();
            let remarks = $("#remarks").val();
            let deliveryTime = $("#deliveryTime").text();
            let data = JSON.parse(sessionStorage.getItem("data"));
            //将数据封装成json对象
            let arr = [];
            let json = {
                registrants: registrants,
                checkInTime: checkInTime,
                remarks: remarks,
                deliveryTime: deliveryTime,
            }
            arr.push(json);
            arr.push(data);
            console.log(arr);
            arr = JSON.stringify(arr);
            //将数据发送到后台
            $.ajax({
                url: "/m-apply/formulatePlan",
                type: "post",
                contentType: "application/json",
                data: arr,
                success: function (data) {
                    if (data) {
                        alert("提交成功");
                        //将sessionStorage中的数据清空
                        sessionStorage.clear();
                        //将sessionStorage中的提交成功的标识设置为true
                        sessionStorage.setItem("submit", "true");
                        //跳转到生产计划管理页面
                        // window.location.href = "/productDesign/list";
                    } else {
                        alert("提交失败");
                    }
                }
            })
        })
    })
    //初始化页面
    function init(){
        //获取sessionStorage中的数据
        let registrants = sessionStorage.getItem("registrants");
        let checkInTime = sessionStorage.getItem("checkInTime");
        let remarks = sessionStorage.getItem("remarks");
        let deliveryTime = sessionStorage.getItem("deliveryTime");
        let data = JSON.parse(sessionStorage.getItem("data"));
        sessionStorage.removeItem("registrants");
        sessionStorage.removeItem("checkInTime");
        sessionStorage.removeItem("remarks");
        sessionStorage.removeItem("deliveryTime");
        //将数据显示到页面中
        $("#registrants").val(registrants);
        $("#checkInTime").text(checkInTime);
        $("#remarks").val(remarks);
        $("#deliveryTime").text(deliveryTime);
        //将数据新增显示到页面中
        if (data != null){
            // sessionStorage.removeItem("data")
            // data = JSON.parse(data);
            for (let i = 0; i < data.length; i++) {
                let obj = data[i];
                let row = "<tr>" +
                    "<td class='ckbox' id='"+obj.id+"'>"+(i+1)+"</td>" +
                    "<td>" + obj.productName + "</td>" +
                    "<td>" + obj.productId + "</td>" +
                    "<td>" + obj.productDescribe+ "</td>" +
                    "<td >"+ obj.num+"</td>" +
                    "<td>" + obj.unit + "</td>" +
                    "<td>" + obj.costPrice + "</td>" +
                    "<td>" + obj.total + "</td>" +
                    "</tr>";
                $("#template").append(row);
            }
        }

    }

</script>
</body>
</html>
